import 'package:base_lib/common/index.dart';
import 'package:base_lib/config.dart';
import 'package:doctor_inquiry_lib/chat_list/entity/doctor_patient_entity.dart'
    as ConversationBean;
import 'package:doctor_inquiry_lib/repository/inquiry_net_intercept.dart';

class IMHttp {
  static HttpManager _httpProxyIns;

  static createHttpProxy(
      {mBaseUrl = Config.doctorBaseUrl,
      codeName = Config.codeName,
      codeSuccessValue = Config.codeSuccessValue,
      msgName = Config.msgName,
      reqTimeOut = Config.reqTimeOut,
      respTimeOut = Config.respTimeOut,
      logTag = "im"}) {
    _httpProxyIns = HttpManager(mBaseUrl,
        CODE_NAME: codeName,
        CODE_SUCCESS_VALUE: codeSuccessValue,
        MSG_NAME: msgName,
        REQ_TIME_OUT: reqTimeOut,
        RESP_TIME_OUT: respTimeOut,
        LOG_TAG: logTag,
        defaultInterceptors: [InquiryNetIntercept()]);
  }

  ///获取UserSig签名
  ///@param userId 账号
  static const GET_USER_SIGN = "api/rp/initial/getUserSig";

  /// 获取UserSig签名
  static Future<ResultBody<String>> getUserSign(String userID) {
    return _httpProxyIns.get<String>(GET_USER_SIGN, (resMap) {
      //{
      //     "code":0,
      //     "data":{
      //         "userSig":"eJw1jksPgjAQhP9Lz4Zs2y0FEg-EGJ8XAU08YqhloxJC8RXjfxdE97QzO99kXyxbp5551NQYFnGl
      // lACA0de9mYZFTHjABu2KU17XVHQ5BBCB1GEwXKgwVUtHGgAAyfuRHFCHXCOC6nbg-x6yXWybTBOK
      // ffsUZ21KsZjH2W5zKGfo0mpyXVqXrhTZPL*7-fgHtnTpn-QBZaiQq-cHXSU0wQ__"
      //     },
      //     "message":"成功"
      // }
      return resMap['data']['userSig'];
    }, queryParams: Map()..['userId'] = userID);
  }

  /// 获取处方详情 - 预览处方页面
  static const INTERFACE_GET_GETRPDETAIL = "api/rp/prescription/getRpDetail";

  /// 获取处方详情 - 预览处方页面
  static Future<ResultBody> getRpDetail(
      String userID, String accessKey, String sign) {
    return _httpProxyIns.post(INTERFACE_GET_GETRPDETAIL, (resMap) {
      return resMap;
    },
        queryParams: Map()
          ..['userId'] = userID
          ..['accessKey'] = accessKey
          ..['sign'] = sign);
  }
  /// 云端混流
  static const INTERFACE_RP_POST_VIDEO_MIX = "api/rp/video/mix";

  /// 云端混流
  static Future<ResultBody> rpVideoMix(
      String userID, String accessKey, String sign) {
    return _httpProxyIns.post(INTERFACE_RP_POST_VIDEO_MIX, (resMap) {
      return resMap;
    },
        queryParams: Map()
          ..['userId'] = userID
          ..['accessKey'] = accessKey
          ..['sign'] = sign);
  }

  /// 发送IM小程序信息回复订阅
  static const INTERFACE_RP_GET_MINIPRO_REPLYMSG =
      "api/rp/wxMsg/sendDoctorReplyMsg";

  /// 发送IM小程序信息回复订阅
  static Future<ResultBody> miniPorReplayMsg(
      String userID, String accessKey, String sign) {
    return _httpProxyIns.post(INTERFACE_RP_GET_MINIPRO_REPLYMSG, (resMap) {
      return resMap;
    },
        queryParams: Map()
          ..['userId'] = userID
          ..['accessKey'] = accessKey
          ..['sign'] = sign);
  }


  /// 身份认证
  /// http://10.0.0.39:6207/auth/login
  /// @param  userId   accessKey     sign
  /// @return
  static const AUTH_LOGIN = "auth/login";

  ///身份认证
  static Future<ResultBody> authLogin(
      String userID, String accessKey, String sign) {
    return _httpProxyIns.post(AUTH_LOGIN, (resMap) {
      return resMap;
    },
        queryParams: Map()
          ..['userId'] = userID
          ..['accessKey'] = accessKey
          ..['sign'] = sign);
  }

  /// 获取roomId
  /// http://10.0.0.39:6207/initial/getRoomId
  /// @param inquiryId
  /// @param userId
  /// @param doctorId
  /// @return
  static const GET_ROOM_ID = "api/rp/initial/getRoomId";

  /// 获取roomId
  static Future<ResultBody> getRoomID(
      String userID, String inquiryId, String doctorId) {
    return _httpProxyIns.get(GET_ROOM_ID, (resMap) {
      return resMap;
    },
        queryParams: Map()
          ..['userId'] = userID
          ..['inquiryId'] = inquiryId
          ..['doctorId'] = doctorId);
  }

  /// 风湿和问诊创建问诊记录
  /// http://10.0.0.210:6111/api/rp/inquiry/create?accessKey=?&sign=?
  /// https://rp-cs.jk.100cbc.com/api/rp/inquiry/create?accessKey=6z63sZ4C095Een5a5H6737WScA6Ml7&sign=e8f5333693cb7ea120e213aed18a9eb8
  /// @param body
  /// @return
  ///   @POST("api/rp/inquiry/create")
  ///   @Headers({
  ///     "url_name:rp",
  ///     "Content-Type:application/json",
  ///     "Accept:application/json"
  ///   })
  static const CREATE_INQUIRY = "api/rp/inquiry/create";

  /// 风湿和问诊创建问诊记录
  static Future<ResultBody> createInquiry(
      String userID, String accessKey, String sign) {
    return _httpProxyIns.postJson(CREATE_INQUIRY, (resMap) {
      return resMap;
    }, jsonData: '');
  }

  /// 刷新处方问诊记录
  /// http://10.0.0.210:6111/api/rp/inquiry/refresh?accessKey=?&sign=?
  /// https://rp-cs.jk.100cbc.com/api/rp/inquiry/refresh?accessKey=6z63sZ4C095Een5a5H6737WScA6Ml7&sign=e8f5333693cb7ea120e213aed18a9eb8
  /// @param body
  /// @return
  /// @POST("api/rp/inquiry/refresh")
  /// @Headers({
  ///   "url_name:rp",
  ///   "Content-Type:application/json",
  ///   "Accept:application/json"
  /// })
  ///
  static const REFRESH_INQUIRY = "api/rp/inquiry/refresh";

  /// 刷新处方问诊记录
  static Future<ResultBody> refreshInquiry(
      String body, String accessKey, String sign) {
    return _httpProxyIns.postJson(REFRESH_INQUIRY, (resMap) {
      return resMap;
    }, jsonData: '');
  }

  ///（处方）辩证开方创建问诊记录
  ///@POST("api/rp/inquiry/createRecord")
  ///@Headers({
  ///  "url_name:rp",
  ///  "Content-Type:application/json",
  ///  "Accept:application/json"
  /// })
  static const CREATE_RP_INQUIRY = "api/rp/inquiry/createRecord";

  static Future<ResultBody> createRPInquiry(
      String body, String accessKey, String sign) {
    return _httpProxyIns.postJson(CREATE_RP_INQUIRY, (resMap) {
      return resMap;
    }, jsonData: '');
  }

  /// 修改问诊状态
  /// http://10.0.0.210:6111/api/rp/inquiry/updateInquiryType?accessKey=?&sign=?
  /// https://rp-cs.jk.100cbc.com/api/rp/inquiry/updateInquiryType?accessKey=6z63sZ4C095Een5a5H6737WScA6Ml7&sign=e8f5333693cb7ea120e213aed18a9eb8
  /// @param
  /// @return
  /// @POST("api/rp/inquiry/updateInquiryType")
  /// @Headers({
  ///   "url_name:rp",
  ///   "Content-Type:application/json",
  ///   "Accept:application/json"
  /// })
  static const UPDATE_INQUIRY_STATUS = "api/rp/inquiry/updateInquiryType";

  /// 修改问诊状态
  static Future<ResultBody> updateInquiryStatus(
      String body, String accessKey, String sign) {
    return _httpProxyIns.postJson(UPDATE_INQUIRY_STATUS, (resMap) {
      return resMap;
    }, jsonData: '');
  }

  /// 修改响应时间
  /// http://10.0.0.210:6111/api/rp/inquiry/responseInquiry?accessKey=?&sign=?
  /// @param
  /// @return
  /// @POST("api/rp/inquiry/responseInquiry")
  /// @Headers({
  ///   "url_name:rp",
  ///   "Content-Type:application/json",
  ///   "Accept:application/json"
  /// })
  static const UPDATE_RESPONSE_TIME = "api/rp/inquiry/responseInquiry";

  static Future<ResultBody> updateResponseTime(
      String body, String accessKey, String sign) {
    return _httpProxyIns.postJson(UPDATE_RESPONSE_TIME, (resMap) {
      return resMap;
    }, jsonData: '');
  }

  /// 结束问诊
  /// http://10.0.0.210:6111/api/rp/inquiry/end?accessKey=?&sign=?
  /// @param
  /// @return
  /// @POST("api/rp/inquiry/end")
  /// @Headers({
  ///   "url_name:rp",
  ///   "Content-Type:application/json",
  ///   "Accept:application/json"
  /// })
  static const END_INQUIRY = "api/rp/inquiry/end";

  static Future<ResultBody> endInquiry(
      String body, String accessKey, String sign) {
    return _httpProxyIns.postJson(END_INQUIRY, (resMap) {
      return resMap;
    }, jsonData: '');
  }

  /// 绑定隐私号码
  /// @Headers({
  ///   "url_name:rp",
  ///   "Content-Type:application/json",
  ///   "Accept:application/json"
  /// })
  static const BIND_PRIVACY_NUMBER = "api/rp/phone/bindPstn";

  static Future<ResultBody> bindPrivacyNumber(
      String body, String accessKey, String sign) {
    return _httpProxyIns.postJson(BIND_PRIVACY_NUMBER, (resMap) {
      return resMap;
    }, jsonData: '');
  }

  /// 请求挂断
  /// @POST("api/rp/phone/bindPstn")
  /// @Headers({
  ///   "url_name:rp",
  ///   "Content-Type:application/json",
  ///   "Accept:application/json"
  /// })
  static Future<ResultBody> hangupPhone(
      String body, String accessKey, String sign) {
    return _httpProxyIns.postJson(BIND_PRIVACY_NUMBER, (resMap) {
      return resMap;
    }, jsonData: '');
  }
}
